import ts from 'rollup-plugin-ts';
import commonjs from '@rollup/plugin-commonjs';
import fs from 'fs';

const outputDir = './dist';

const rmdir = (dir) => fs.existsSync(dir) && fs.statSync(dir).isDirectory() && fs.rmSync(dir, { recursive: true });

export default {
  input  : 'src/index.ts',
  output : [
    {
      file: `${outputDir}/index.js`, format: 'cjs'
    }, {
      file: `${outputDir}/index.mjs`, format: 'esm'
    }
  ],
  plugins: [
    rmdir(outputDir),
    ts({}), commonjs({
      include: ['node_modules/**'], ignoreGlobal: false
    })
  ]
};